package com.stylefeng.guns.rest.proxy.staticProxy;

import com.stylefeng.guns.rest.proxy.IOrderService;
import com.stylefeng.guns.rest.proxy.Order;
import com.stylefeng.guns.rest.proxy.OrderServiceImpl;
import com.stylefeng.guns.rest.proxy.db.DataSourceContextHolder;

public class OrderStaticProxy {
    private IOrderService iorderService;

    public int insert(Order order) {
        beforeMethod();
        iorderService = new OrderServiceImpl();
        Integer userId = order.getUserId();
        int dbRouter = userId % 2;
        System.out.println("静态代理分配到的路由key" + dbRouter);
        DataSourceContextHolder.setDbType(String.valueOf(dbRouter));
        afterMethod();
        return iorderService.insert(order);
    }

    public void beforeMethod() {

    }

    public void afterMethod() {

    }
}
